{template '_header'}

<div class="page-header">
    当前位置：<span class="text-primary">{if !empty($level['id'])}编辑{else}添加{/if}门店{if !empty($item['id'])}({$item['mendianname']}){/if}</span>
</div>

<div class="page-content">
    <div class="page-sub-toolbar">
        <span class=''>
            {ifp 'mendian.edit'}
                <a class="btn btn-primary btn-sm" href="{php echo webUrl('mendian/post')}">添加新门店</a>
            {/if}
            {if empty($opid) && empty($chid) && empty($maid)}
		        <a class="btn btn-default  btn-sm" href="{php echo webUrl('mendian/index')}">返回列表</a>
            {else}
		        <a class="btn btn-default  btn-sm" href="{php echo webUrl('mendian/index', array('opid'=>$opid, 'chid'=>$chid, 'maid'=>$maid))}">返回列表</a>
            {/if}
        </span>
    </div>

<form id="setform"  {ifp 'mendian.edit'}action="" method="post"{/if} class="form-horizontal form-validate">
<input type="hidden" id="tab" name="tab" value="#tab_basic" />
<input type="hidden" name="opid" value="{$opid}" />
<input type="hidden" name="chid" value="{$chid}" />
<input type="hidden" name="maid" value="{$maid}" />

<div class="tabs-container">

    <ul class="nav nav-tabs" id="myTab">
        <li  {if empty($_GPC['tab']) || $_GPC['tab']=='basic'}class="active"{/if}><a href="#tab_basic">基本信息</a></li>
        <li  {if $_GPC['tab']=='more'}class="active"{/if}><a href="#tab_more">更多信息</a></li>
        <li  {if $_GPC['tab']=='inpay'}class="active"{/if}><a href="#tab_inpay">支付设置</a></li>
        <!--<li  {if $_GPC['tab']=='merch'}class="active"{/if}><a href="#tab_merch">多商户</a></li>-->
        <!--<li {if $_GPC['tab']=='plugin'}class="active"{/if}><a href="#tab_plugin">应用权限</a></li>-->
    </ul>

    <div class="tab-content ">
        <div class="tab-pane {if empty($_GPC['tab']) || $_GPC['tab']=='basic'}active{/if}" id="tab_basic">{template 'mendian/post/basic'}</div>
        <div class="tab-pane {if $_GPC['tab']=='more'}active{/if}" id="tab_more">{template 'mendian/post/more'}</div>
        <div class="tab-pane {if $_GPC['tab']=='inpay'}active{/if}" id="tab_inpay">{template 'mendian/post/inpay'}</div>
        <!--<div class="tab-pane {if $_GPC['tab']=='merch'}active{/if}" id="tab_merch"></div>-->
        <!--<div class="tab-pane {if $_GPC['tab']=='plugin'}active{/if}" id="tab_plugin"></div>-->
    </div>
</div>

{ifp 'mendian.edit'}
<div class="form-group">
    <label class="col-sm-2 control-label"></label>
    <div class="col-sm-9 col-xs-12">
        <input type="submit"  value="提交" class="btn btn-primary" />
    </div>
</div>
{/if}

</form>
</div>
<script language='javascript'>
    require(['bootstrap'], function () {
        $('#myTab a').click(function (e) {
            $('#tab').val($(this).attr('href'));
            e.preventDefault();
            $(this).tab('show');
        })
    });
</script>

<script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script>
<script>
    var lat='';
    var lng='';
    {if !empty($item['lat'])}
    lat={$item['lat']};
    lng={$item['lng']};
    {/if}

    var _opid = {php echo intval($opid)};

    function check_lat_lng() {
        var temp_lat=$("input[name='location[lat]']").val();
        var temp_lng=$("input[name='location[lng]']").val();
        if(temp_lat!=lat || temp_lng!=lng)
        {
            var latLng = new qq.maps.LatLng(temp_lat,temp_lng);
            geocoder.getAddress(latLng);
            lat=temp_lat;
            lng=temp_lng;
        }
    }

    var geocoder = new qq.maps.Geocoder({
        complete: function (result) {
            if(_opid == 0) {
                $('#province').val(result.detail.addressComponents.province);
                $('#city').val(result.detail.addressComponents.city);
                $('#dist').val(result.detail.addressComponents.district);
                $('#town').val(result.detail.addressComponents.town);
                $('#street').val(result.detail.addressComponents.street);

                var address = result.detail.addressComponents.province + ' ' + result.detail.addressComponents.city + ' ' + result.detail.addressComponents.district + ' ' + result.detail.addressComponents.town + ' ' + result.detail.addressComponents.street;
                $('#address2').html(address);
            }

        }
    });


    setInterval(function(){
        check_lat_lng();
    },500);

</script>

{template '_footer'}